<template>
	<view>
		<cu-custom bgColor="bgmain" :isBack="true">
		    <view slot="content">商家优惠券</view>
		</cu-custom>
		
			
		<view v-for="(item,index) in dataList" :key="index" class="item flex">
			<image :src="item.business_image" mode="aspectFill"></image>
			<view style="width: 100%;">
				<view class="flex align-center justify-between">
					<view>
						<view class="name">{{item.business_name}}</view>
						<view class="type">
						<!-- {{item.type==1?'满减券':'立减券'}} -->
						{{ item.c_name }}
						</view>
					</view>
					<view class="price"><text class="text-df">￥</text>{{item.price}}</view>
				</view>
				<view class="flex justify-between align-center" style="border-top: 1rpx dotted #D1D1D1;padding-top: 16rpx;">
					<text class="text-sm">全场商品通用，不可叠加使用</text>
					<view class="use" v-if="store_id" @click="selectCoupon(item)">使用</view>
					<view class="use" v-else @click="go('/gc_school/pages/foold/foold?id='+item.store_id)">去使用</view>
				</view>
			</view>
		</view>
			
		
	</view>
</template>

<script>
	var app = getApp();
export default {
		data(){
			return{
				dataList:[],
				page:1,
				is_loadmore:true,
				price:0,
				store_id:0
			}
		},
		onLoad(options) {
			console.log(options);
			this.store_id = options.store_id || 0
			// this.store_id = 2
			this.price=options.price||0
			this.getList()
		},
		methods:{
			selectCoupon(item){
				console.log("this.price<item.price="+this.price*1 < item.price*1);
				if (item.type == 1 && item.cut_num * 1> this.price * 1) {
					this.tips.tips("该优惠券不可用")
					return
				}
				if (this.price*1 < item.price*1) {
					this.tips.tips("该优惠券不可用")
					return
				}
				uni.$emit("selectCounper", item)
				uni.navigateBack({ delta: 1 })
			},
			getList()
			{
				var self = this;

				let data={
					limit: 10,
					page: this.page,
					s_id: uni.getStorageSync('schoolId')
				}
				if (this.store_id >0) {
					data.store_id=this.store_id
				}
				app.globalData.util.request({
					url: 'UserCoupon/userStoreCoupon',
					data,
					success(res) {
						console.log(res)
						if (res.data.data.length < 4) {
							self.is_loadmore = false;
						}
						self.dataList = [...self.dataList,...res.data.data]
						console.log("self.list",self.dataList)
					}
				}, true);
			}
		}
	}
</script>

<style lang="scss">
	.item{
		background-color: white;
		margin: 30rpx;
		padding: 25rpx 20rpx;
		border-radius: 20rpx;
		image{
			width: 120rpx;
			height: 120rpx;
			border-radius: 10rpx;
			margin-right: 20rpx;
			flex-shrink: 0;
		}
		.name{
			color: #232323;
			font-size: 30rpx;
			font-weight: bold;
		}
		.type{
			color: #FF4C4D;
			font-size: 24rpx;
			line-height: 50rpx;
		}
		.price{
			color: #FF4C4D;
			font-size: 50rpx;
			font-weight: bold;
		}
		.use{
			background: linear-gradient(90deg, #FF5951 0%, #FF816F 100%);
			border-radius: 10rpx;
			color: #FFFFFF;
			font-size: 22rpx;
			padding: 10rpx 20rpx;
		}
	}
</style>